package t4;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Set;

import t4bean.SalesvolumeRecordBean;
import t4bean.StallBean;

/**
 * 显示三个销量最高的水果
 *
 */
public class ShowThreeFruit {
	public void showThreeFruit(StallBean stall) {
		List<SalesvolumeRecordBean> srList = stall.getSalList();

		HashMap<Integer, String> h1 = new HashMap<Integer, String>();

		int n = 0;
		for (SalesvolumeRecordBean sr : srList) {
			for (Integer key : h1.keySet()) {
				if (sr.getFruit().getName().equals(h1.get(key))) {
					key = key + sr.getSalesVolume();
					n = 1;
				}
			}
			if (n == 0) {
				h1.put(sr.getSalesVolume(), sr.getFruit().getName());
			} else {
				n = 0;
			}
		}

		Set<Integer> set = h1.keySet();
		Object[] arr = set.toArray();
		Arrays.sort(arr);
		int l = h1.size();
		int ll = 0;
		for (Object key : arr) {
			ll++;
			if (ll >= l - 1 - 3) {
				System.out.println("水果：" + h1.get(key));
				System.out.println("销售数量：" + key);
			}
		}
		System.out.println();
	}
}
